package com.zzb.framework.utils;

import com.zzb.framework.common.BaseEntity;
import org.apache.commons.collections4.CollectionUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 继承BaseEntity的实体的工具类
 * Created by zhangzhenbin on 17-3-13.
 */
public class BaseEntityMisc {
    /**将实体列表转为以id为键的hashMap*/
    public static  <T extends BaseEntity> Map<Serializable,T> parseToKeyMap(List<T> entities){
        final Map<Serializable, T> map = new HashMap<>();
        if(CollectionUtils.isNotEmpty(entities)) entities.forEach(t -> map.put(t.getId(), t));
        return map;
    }

}
